package com.mooral.context;


import javax.servlet.http.HttpSession;

import com.mooral.web.constant.Constants;



public class ContextSession {
    public static final ThreadLocal<Context> context = new ThreadLocal<Context>();

    public static void initContext(HttpSession session) {
		Context ctx = (Context) context.get();
		if (ctx == null) {
		    ctx = new Context();
		    ctx.setSessionId(session.getId());
		    ctx.setApplicationName(session.getServletContext().getContextPath().substring(1));
		    context.set(ctx);
		}
		session.setAttribute(Constants.CONTEXT_NAME, ctx);
		ctx.setSession(session);
    }

   
    public static void initContext() {
		Context ctx = (Context) context.get();
		if (ctx == null) {
		    ctx = new Context();
		    ctx.setSessionId(Thread.currentThread().getName());
		    context.set(ctx);
		}
    }

    public static Context getCurrentContext() {
    	return (Context) context.get();
    }

    public static void disposeContext() {
    	context.set(null);
    }
    
    
    
}
